#Clear R
rm(list=ls())

# Load necessary libraries
library(readstata13)

#load datasets
NFC12<-read.dta13("Study2_NFC.dta") #ignore warnings - all about labels
NFC11<-read.dta13("Study2_NFC11.dta") #ignore warnings - all about labels
Experiment<-read.dta13("Study2_Experiment.dta") #ignore warnings - all about labels
Ideology<-read.dta13("Study2_ideology.dta") #ignore warnings - all about labels

#merge datasets into one dataset
Experiment1 <- merge(Experiment, NFC12,by="nomem_encr", all=T)
Experiment2 <- merge(Experiment1, NFC11, by="nomem_encr", all=T)
nc <-  merge(Experiment2, Ideology, by="nomem_encr", all=T)

################
#Create items
################

###################
#NFC in 2012
###################
#1: cp12e166 "I would prefer complex to simple problems" 
nc$y12_NFC1 <- nc$cp12e166
#2 cp12e167 "I like to have the responsibility of handling a situation that requires a lot of thinking" 
nc$y12_NFC2 <- nc$cp12e167
#3 recoded item: cp12e168  "Thinking is not my idea of fun" 
nc$y12_NFC3 <- 8-nc$cp12e168
#4 recoded item: cp12e169 "I would rather do something that requires little thought than something that is sure to challenge my thinking abilities" 
nc$y12_NFC4 <- 8-nc$cp12e169
#5 recoded item: cp12e170 "I try to anticipate and avoid situations where there is likely chance that I will have to think in depth about something" 
nc$y12_NFC5 <- 8-nc$cp12e170
#6 cp12e171 "I find satisfaction in deliberating hard and for long hours" 
nc$y12_NFC6 <- nc$cp12e171
#7 recoded item: cp12e172 "I only think as hard as I have to"   
nc$y12_NFC7 <- 8-nc$cp12e172
#8 recoded item: cp12e173 "I prefer to think about small, daily projects to long-term ones" 
nc$y12_NFC8 <- 8-nc$cp12e173
#9 recoded item cp12e174 "I like tasks that require little thought once I've learned them" 
nc$y12_NFC9 <- 8-nc$cp12e174
#10 cp12e175 "The idea of relying on thought to make my way to the top appeals to me" 
nc$y12_NFC10 <- nc$cp12e175
#11 cp12e176 "I really enjoy a task that involves coming up with new solutions to problems" 
nc$y12_NFC11 <- nc$cp12e176
#12 cp12e177 recoded item cp12e177 "Learning new ways to think doesn't excite me very much" 
nc$y12_NFC12 <- 8-nc$cp12e177
#13 cp12e178 "I prefer my life to be filled with puzzles that I must solve" 
nc$y12_NFC13 <- nc$cp12e178
#14 cp12e179 "The notion of thinking abstractly is appealing to me" 
nc$y12_NFC14 <- nc$cp12e179
#15 cp12e180 "I would prefer a task that is intellectual, difficult and important to one that is somewhat important but does not require much thought" 
nc$y12_NFC15 <- nc$cp12e180
#16 cp12e181 recoded item:  "I feel relief rather than satisfaction after completing a task that required a lot of mental effort" 
nc$y12_NFC16 <- 8-nc$cp12e181
#17 cp12e182 recoded item:  "It's enough for me that somthing gets the job done; I don't care how or why it works"
nc$y12_NFC17 <- 8-nc$cp12e182
#18 cp12_NFC18 "I usually end up deliberating issues even when they do not affect me personally" 
nc$y12_NFC18 <- nc$cp12e183

###################
#NFC in 2011
###################
#1: cp12e166 "I would prefer complex to simple problems" 
nc$y11_NFC1 <- nc$cp11d166
#2 cp12e167 "I like to have the responsibility of handling a situation that requires a lot of thinking" 
nc$y11_NFC2 <- nc$cp11d167
#3 recoded item: cp12e168  "Thinking is not my idea of fun" 
nc$y11_NFC3 <- 8-nc$cp11d168
#4 recoded item: cp12e169 "I would rather do something that requires little thought than something that is sure to challenge my thinking abilities" 
nc$y11_NFC4 <- 8-nc$cp11d169
#5 recoded item: cp12e170 "I try to anticipate and avoid situations where there is likely chance that I will have to think in depth about something" 
nc$y11_NFC5 <- 8-nc$cp11d170
#6 cp12e171 "I find satisfaction in deliberating hard and for long hours" 
nc$y11_NFC6 <- nc$cp11d171
#7 recoded item: cp12e172 "I only think as hard as I have to"   
nc$y11_NFC7 <- 8-nc$cp11d172
#8 recoded item: cp12e173 "I prefer to think about small, daily projects to long-term ones" 
nc$y11_NFC8 <- 8-nc$cp11d173
#9 recoded item cp12e174 "I like tasks that require little thought once I've learned them" 
nc$y11_NFC9 <- 8-nc$cp11d174
#10 cp12e175 "The idea of relying on thought to make my way to the top appeals to me" 
nc$y11_NFC10 <- nc$cp11d175
#11 cp12e176 "I really enjoy a task that involves coming up with new solutions to problems" 
nc$y11_NFC11 <- nc$cp11d176
#12 cp12e177 recoded item cp12e177 "Learning new ways to think doesn't excite me very much" 
nc$y11_NFC12 <- 8-nc$cp11d177
#13 cp12e178 "I prefer my life to be filled with puzzles that I must solve" 
nc$y11_NFC13 <- nc$cp11d178
#14 cp12e179 "The notion of thinking abstractly is appealing to me" 
nc$y11_NFC14 <- nc$cp11d179
#15 cp12e180 "I would prefer a task that is intellectual, difficult and important to one that is somewhat important but does not require much thought" 
nc$y11_NFC15 <- nc$cp11d180
#16 cp12e181 recoded item:  "I feel relief rather than satisfaction after completing a task that required a lot of mental effort" 
nc$y11_NFC16 <- 8-nc$cp11d181
#17 cp12e182 recoded item:  "It's enough for me that somthing gets the job done; I don't care how or why it works"
nc$y11_NFC17 <- 8-nc$cp11d182
#18 cp12_NFC18 "I usually end up deliberating issues even when they do not affect me personally" 
nc$y11_NFC18 <- nc$cp11d183

nc$nfc1 <- with(nc,rowMeans(data.frame(y11_NFC1,y12_NFC1),na.rm=T))
nc$nfc2 <- with(nc,rowMeans(data.frame(y11_NFC2,y12_NFC2),na.rm=T))
nc$nfc3 <- with(nc,rowMeans(data.frame(y11_NFC3,y12_NFC3),na.rm=T))
nc$nfc4 <- with(nc,rowMeans(data.frame(y11_NFC4,y12_NFC4),na.rm=T))
nc$nfc5 <- with(nc,rowMeans(data.frame(y11_NFC5,y12_NFC5),na.rm=T))
nc$nfc6 <- with(nc,rowMeans(data.frame(y11_NFC6,y12_NFC6),na.rm=T))
nc$nfc7 <- with(nc,rowMeans(data.frame(y11_NFC7,y12_NFC7),na.rm=T))
nc$nfc8 <- with(nc,rowMeans(data.frame(y11_NFC8,y12_NFC8),na.rm=T))
nc$nfc9 <- with(nc,rowMeans(data.frame(y11_NFC9,y12_NFC9),na.rm=T))
nc$nfc10 <- with(nc,rowMeans(data.frame(y11_NFC10,y12_NFC10),na.rm=T))
nc$nfc11 <- with(nc,rowMeans(data.frame(y11_NFC11,y12_NFC11),na.rm=T))
nc$nfc12 <- with(nc,rowMeans(data.frame(y11_NFC12,y12_NFC12),na.rm=T))
nc$nfc13 <- with(nc,rowMeans(data.frame(y11_NFC13,y12_NFC13),na.rm=T))
nc$nfc14 <- with(nc,rowMeans(data.frame(y11_NFC14,y12_NFC13),na.rm=T))
nc$nfc15 <- with(nc,rowMeans(data.frame(y11_NFC15,y12_NFC14),na.rm=T))
nc$nfc16 <- with(nc,rowMeans(data.frame(y11_NFC16,y12_NFC16),na.rm=T))
nc$nfc17 <- with(nc,rowMeans(data.frame(y11_NFC17,y12_NFC17),na.rm=T))
nc$nfc18 <- with(nc,rowMeans(data.frame(y11_NFC18,y12_NFC18),na.rm=T))

#*****************************
#hear see the treatment
#*****************************
nc$dumHearSee[nc$ib12a031==1]=0
nc$dumHearSee[nc$ib12a031==2]=1

#*****************************
#Dependent Variable
#*****************************
nc$dv_agree_partyposition<- ((nc$ib12a045-1)/4)

#*****************************
#*Treatment: right or center-right
#*****************************
nc$t_message[nc$ib12a001==1]=0
nc$t_message[nc$ib12a001==2]=1

#****************************
#*Treatment: party cue
#*****************************
nc$t_partycue[nc$ib12a004==1]=1
nc$t_partycue[nc$ib12a004==2]=0

#****************************
#*Treatment: gender
#*****************************
nc$t_gender[nc$ib12a003==1]=0
nc$t_gender[nc$ib12a003==2]=1

#*****************************
#*Treatment: aggressive speech
#*****************************
nc$t_aggressive[nc$ib12a002==1]=1
nc$t_aggressive[nc$ib12a002==2]=0

#*****************************
#Create 18-item scale
#*****************************
nc$comb_NFC_full<-(rowMeans(data.frame(nc$nfc1, nc$nfc2, nc$nfc3, nc$nfc4, nc$nfc5, nc$nfc6, nc$nfc7, nc$nfc8, nc$nfc9, nc$nfc10, nc$nfc11, nc$nfc12, nc$nfc13, nc$nfc14, nc$nfc15, nc$nfc16, nc$nfc17, nc$nfc18), na.rm=T))
nc$comb_NFC_full<-((nc$comb_NFC_full-1)/6)

#*****************************
#Create 6-item scale
#*****************************
nc$comb_NFC_Bullock<-(rowMeans(data.frame(nc$nfc1, nc$nfc2, nc$nfc3, nc$nfc6, nc$nfc8, nc$nfc16), na.rm=T))
nc$comb_NFC_Bullock<-((nc$comb_NFC_Bullock-1)/6)

#*****************************
#Create 2-item scale
#*****************************
nc$comb_NFC_ANES<-(rowMeans(data.frame(nc$nfc1, nc$nfc2), na.rm=T))
nc$comb_NFC_ANES<-((nc$comb_NFC_ANES-1)/6)

save(nc, file="Study2_data.Rdta")
